﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using freemarker.template;
using Freemarker.Net;
using java.util;
using System.Threading;
using System.Globalization;
using Freemarker.Net.Directive;

namespace ConsoleApplication1 {
    class Program {

        static void Main(string[] args) {
            /* ------------------------------------------------------------------- */
            /* You should do this ONLY ONCE in the whole application life-cycle:   */

            /* Create and adjust the configuration */
            Configuration cfg = new Configuration();
            cfg.setDirectoryForTemplateLoading(
                    new java.io.File(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)));
            NetObjectWrapper wrapper = new NetObjectWrapper();
            wrapper.AddExtensionNamespace("ConsoleApplication1");
            cfg.setObjectWrapper(wrapper);

            /* ------------------------------------------------------------------- */
            /* You usually do these for many times in the application life-cycle:  */

            /* Get or create a template */
            try {
                Template temp = cfg.getTemplate("test.ftl", "utf-8");
                Point point = new Point { X = 1, Y = 5 };                
                /* Create a data-model */
                Dictionary<string, object> data = new Dictionary<string, object>{
                    {"data", point},
                    {"resource", ResourceManagerDirectiveModel.Instance}
                };
            /* Merge data-model with template */
            java.io.Writer output = new JavaTextWriter(Console.Out);
            temp.process(data, output);
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("fr");
            temp.process(data, output);
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("ru");
            temp.process(data, output);
            output.flush();
            }
            catch (Exception e) {
                Console.WriteLine(e);
            }
            Console.ReadLine();
        }
    }

    public class Point {
        public int X { get; set; }
        public int Y { get; set; }

        public void Move(int x, int y) {
            this.X = x;
            this.Y = y;
        }

        public void Reset() {
            this.X = 0;
            this.Y = 0;
        }
    }
    
    public static class PointExtensions {
        public static void Invert(this Point p){
            p.X = -p.X;
            p.Y = -p.Y;
        }
    }
}
